using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class StartupScreen : MonoBehaviour {

    [SerializeField]
    Image _overlayImage;

    [SerializeField]
    Outline _titleOutline;

    [SerializeField]
    Outline _playOutline;

    float _outlineTimerDelay = .5f;
    float _outlineTimer;

    void Awake() {
        OverlayEffect();
    }

    void Update() {
        if(_outlineTimer > 0) {
            _outlineTimer = Mathf.Max(_outlineTimer - Time.deltaTime, 0);

            float alpha = Mathf.Lerp(0, .5f, 1 - (_outlineTimer / _outlineTimerDelay));

            _titleOutline.effectColor = new Color(1, 1, 1, alpha);
            _playOutline.effectColor = new Color(1, 1, 1, alpha);
        }
    }

    public void OverlayEffect() {
        StopCoroutine("DisableOverlay");

        _titleOutline.effectColor = new Color(1, 1, 1, 0);
        _playOutline.effectColor = new Color(1, 1, 1, 0);

        _overlayImage.enabled = true;
        _overlayImage.color = Color.black;
        _overlayImage.CrossFadeAlpha(0, 1, true);

        StartCoroutine("DisableOverlay", 1);
    }

    IEnumerator DisableOverlay(float time) {
        yield return new WaitForSeconds(time);

        _overlayImage.enabled = false;
        _outlineTimer = _outlineTimerDelay;
    }
}